package com.yxh.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import android.os.Environment;
import android.util.Log;

public class LogUtil {
    /*** log ***/
    public static void e(String content) {
        if (Constant.IS_LOG) {// 后台输出
            Log.e("luoming", content + "");
        } else {// 输出到log.txt
            // writeLogToSD("<br>" + PM25DeviceUtil.getCurrentTime()
            // + "*****************<br>" + content);
        }
    }

    /*** write log to sdcard ***/
    @SuppressWarnings("unused")
    private static void writeLogToSD(String content) {
        FileWriter fos = null;
        try {
            boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
            File dir = null;
            if (sdCardExist) {
                dir = new File(Environment.getExternalStorageDirectory().toString() + File.separator
                        + "360_air_log.txt");
                if (!dir.exists()) {
                    dir.createNewFile();
                }

                fos = new FileWriter(dir, true);
                fos.write(content);
                fos.flush();
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
